package cn.itcast.usermanage.service;

import cn.itcast.usermanage.dao.UserMapper;
import cn.itcast.usermanage.pojo.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public Long count() {
        Long total = this.userMapper.count();
        return total;
    }

    public List<User> queryList(Integer start, Integer rows) {
        List<User> userList = this.userMapper.queryUserListPage(start, rows);
        return userList;
    }



    public PageInfo<User> queryUserAll(Integer page, Integer rows) {
//       将分页工具开启,必须放在查询之前
        PageHelper.startPage(page, rows);
        //调用查询的方法
        List<User> users = this.userMapper.queryUserAll();
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return  pageInfo;
    }


    public void saveUser(User user) {
        this.userMapper.saveUser(user);
    }

    public void delete(String ids) {
        this.userMapper.delete(ids);
    }
}
